package org.googlecode.openapi_java;

import org.json.JSONException;
import org.json.JSONObject;

public class Group {
    int gid;
    String name;
    String photo;
    boolean isClosed;
    boolean isDeleted;

    public static Group fromJSON(JSONObject jsonObject) throws JSONException {
        System.out.println("jsonObject = " + jsonObject);
        Group group = new Group();
        group.gid = jsonObject.getInt("gid");
        group.name = jsonObject.getString("name");
        group.photo = jsonObject.getString("photo");
        group.isDeleted = jsonObject.get("is_closed") == JSONObject.NULL;
        if (!group.isDeleted) {
            group.isClosed = jsonObject.getInt("is_closed") == 1;
        }
        return group;
    }

    @Override
    public String toString() {
        return "Group{" +
                "gid=" + gid +
                ", name='" + name + '\'' +
                ", photo='" + photo + '\'' +
                ", isClosed=" + isClosed +
                ", isDeleted=" + isDeleted +
                '}';
    }
}
